package com.jrx.anytxn.transaction.mapper.ext;

import com.jrx.anytxn.transaction.entity.TlPaymentLog;
import com.jrx.anytxn.transaction.entity.TlWaivePaymentLog;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * 还款流水扩展
 *
 * @author haopu.zheng
 * date: 2019/8/24
 **/
public interface ExtTlWaivePaymentLogMapper {

    /**
     * 根据customerId、loanId查询还款流水tl_payment_log，统计存在sum_status非最终态（S/F)的记录
     *
     * @param customerId 客户id
     * @param status     状态数组
     * @param tenantId   租户id
     * @return int
     * @author : zhenghaopu
     * date: 2019/9/25
     */
    List<TlWaivePaymentLog> selectByCustomerIdAndSumStatus(@Param(value = "customerId") String customerId,
                                                           @Param(value = "status") String[] status,
                                                           @Param(value = "tenantId") String tenantId);

    /**
     * 根据还款流水号查询流水状态
     *
     * @param paymentSeqNo 还款流水
     * @param customerId   客户id
     * @param tenantId     租户id
     * @return 还款流水信息
     */
    TlWaivePaymentLog selectPaymentStatusByPaymentSeqNo(@Param(value = "paymentSeqNo") String paymentSeqNo,
                                                        @Param(value = "customerId") String customerId,
                                                        @Param(value = "tenantId") String tenantId);

    /**
     * 根据贷款ID/还款流水状态/客户号查询还款流水
     *
     * @param loanId     贷款ID
     * @param status     还款流水状态
     * @param customerId 客户号
     * @param tenantId   租户id
     * @return com.jrx.anytxn.transaction.entity.TlPaymentLog 还款流水信息
     * @author zhenghaopu
     * date: 2019/8/19 15:50
     */
    TlWaivePaymentLog selectPaymentLogByLoanIdAndStatus(@Param(value = "loanId") String loanId,
                                                        @Param(value = "status") String status,
                                                        @Param(value = "customerId") String customerId,
                                                        @Param(value = "paymentType") String paymentType,
                                                        @Param(value = "tenantId") String tenantId);

    /**
     * 批量插入还款流水
     *
     * @param tlPaymentLogs 还款流水信息
     */
    int batchInsert(List<TlWaivePaymentLog> tlPaymentLogs);

    /**
     * 根据主键、客户id及租户id修改还款流水
     *
     * @param tlPaymentLog 还款流水
     */
    int updateByIdAndCustomerIdAndTenantId(TlWaivePaymentLog tlPaymentLog);

    /**
     * 根据请求流水号查询流水状态
     *
     * @param payId      请求流水号
     * @param customerId 客户id
     * @param tenantId   租户id
     * @return 还款流水信息
     */
    TlWaivePaymentLog selectByPayId(@Param(value = "payId") String payId,
                                    @Param(value = "customerId") String customerId,
                                    @Param(value = "tenantId") String tenantId);

    /**
     * 批量 - 根据状态查询还款流水
     *
     * @param sumStatus
     * @return
     */
    List<TlWaivePaymentLog> selectBySumStatusNotPayType(@Param(value = "sumStatus") String sumStatus,
                                                        @Param(value = "payType") String payType,
                                                        @Param(value = "grayVersion") String grayVersion);

    /**
     * 批量更新还款流水
     *
     * @param updateLogList
     * @return
     */
    int batchUpdateLog(List<TlWaivePaymentLog> updateLogList);

    /**
     * 批量 - 根据状态查询还款流水
     *
     * @param sumStatus
     * @return
     */
    List<TlWaivePaymentLog> selectBySumStatus(@Param(value = "sumStatus") String sumStatus);


    /**
     * 批量 - 根据状态、还款类型、业务日期查询还款流水
     * 批扣初始化使用
     *
     * @param sumStatus    最终态
     * @param paymentType  还款类型
     * @param businessDate 业务日期
     * @return 还款流水
     */
    List<TlWaivePaymentLog> selectBySumStatusAndPayTypeForBatch(@Param(value = "sumStatus") String sumStatus,
                                                                @Param(value = "paymentType") String paymentType,
                                                                @Param(value = "businessDate") Date businessDate);

    /**
     * 批扣 - 根据状态、还款类型、业务日期查询还款流水
     * 批量扣款
     *
     * @param sumStatus    最终态
     * @param paymentType  还款类型
     * @param businessDate 业务日期
     * @return 还款流水
     */
    List<TlWaivePaymentLog> selectBySumStatusAndBusinessDateForBatch(@Param(value = "sumStatus") String sumStatus,
                                                                     @Param(value = "paymentType") String paymentType,
                                                                     @Param(value = "businessDate") Date businessDate);

    /**
     * 根据最终态、还款类型、渠道、客户查询还款流水
     *
     * @param customerId    客户
     * @param channel       渠道
     * @param paymentType   还款类型
     * @param sumStatusList 状态列表
     * @return 还款流水
     */
    List<TlWaivePaymentLog> selectListBySumStatusAndPayTypeForBatch(@Param("customerId") String customerId,
                                                                    @Param("channel") String channel,
                                                                    @Param("paymentType") String paymentType,
                                                                    @Param("sumStatusList") List<String> sumStatusList);

    /**
     * 批量-批量更新还款流水
     *
     * @param updateLogList
     * @return
     */
    int batchUpdateLogForBatch(List<TlWaivePaymentLog> updateLogList);


    /**
     * 根据还款流水号 查询 流水表
     *
     * @param seqNo 还款交易流水号
     * @return 还款流水信息
     */
    TlWaivePaymentLog selectBySeqNoAndTenantId(@Param(value = "seqNo") String seqNo, @Param(value = "tenantId") String tenantId);

    /**
     * 按流水号及状态查询还款流水列表
     *
     * @param seqNoList  流水号列表
     * @param statusList 状态列表
     * @param customerId 客户id
     * @param tenantId   租户id
     * @return 还款流水列表
     */
    List<TlWaivePaymentLog> selectBySeqNoListAndStatusList(@Param(value = "seqNoList") List<String> seqNoList,
                                                           @Param(value = "statusList") List<String> statusList,
                                                           @Param(value = "customerId") String customerId,
                                                           @Param(value = "tenantId") String tenantId);

    /**
     * 按照更新时间获取还款流水
     *
     * @param startTime
     * @param endTime
     * @return
     */
    List<TlWaivePaymentLog> selectByUpdateTimeForBatch(@Param("startTime") String startTime, @Param("endTime") String endTime);

    /**
     * 根据最终态、渠道、客户查询还款流水
     *
     * @param customerId    客户
     * @param channel       渠道
     * @param sumStatusList 状态列表
     * @return 还款流水
     */
    List<TlWaivePaymentLog> selectListBySumStatusForBatch(@Param("customerId") String customerId,
                                                          @Param("channel") String channel,
                                                          @Param("sumStatusList") List<String> sumStatusList);

    /**
     * 查询代偿回购流水
     * 批量扣款
     *
     * @param sumStatus       最终态
     * @param paymentTypeList 还款类型
     * @param businessDate    业务日期
     * @return 还款流水
     */
    List<TlWaivePaymentLog> selectBySumStatusAndPaymentTypForBatch(@Param(value = "sumStatus") String sumStatus,
                                                                   @Param(value = "paymentTypeList") List<String> paymentTypeList,
                                                                   @Param(value = "businessDate") Date businessDate);

}